home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / python2.5 / os.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-05-11  |  23.2 KB  |  835 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. """OS routines for Mac, NT, or Posix depending on what system we're on.
  5.  
  6. This exports:
  7.   - all functions from posix, nt, os2, mac, or ce, e.g. unlink, stat, etc.
  8.   - os.path is one of the modules posixpath, ntpath, or macpath
  9.   - os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
  10.   - os.curdir is a string representing the current directory ('.' or ':')
  11.   - os.pardir is a string representing the parent directory ('..' or '::')
  12.   - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\\\')
  13.   - os.extsep is the extension separator ('.' or '/')
  14.   - os.altsep is the alternate pathname separator (None or '/')
  15.   - os.pathsep is the component separator used in $PATH etc
  16.   - os.linesep is the line separator in text files ('\\r' or '\\n' or '\\r\\n')
  17.   - os.defpath is the default search path for executables
  18.   - os.devnull is the file path of the null device ('/dev/null', etc.)
  19.  
  20. Programs that import and use 'os' stand a better chance of being
  21. portable between different platforms.  Of course, they must then
  22. only use functions that are defined by all platforms (e.g., unlink
  23. and opendir), and leave all pathname manipulation to os.path
  24. (e.g., split and join).
  25. """
  26. import sys
  27. _names = sys.builtin_module_names
  28. __all__ = [
  29.     'altsep',
  30.     'curdir',
  31.     'pardir',
  32.     'sep',
  33.     'pathsep',
  34.     'linesep',
  35.     'defpath',
  36.     'name',
  37.     'path',
  38.     'devnull',
  39.     'SEEK_SET',
  40.     'SEEK_CUR',
  41.     'SEEK_END']
  42.  
  43. def _get_exports_list(module):
  44.     
  45.     try:
  46.         return list(module.__all__)
  47.     except AttributeError:
  48.         return _[1]
  49.     except:
  50.         []
  51.  
  52.  
  53. if 'posix' in _names:
  54.     name = 'posix'
  55.     linesep = '\n'
  56.     from posix import *
  57.     
  58.     try:
  59.         from posix import _exit
  60.     except ImportError:
  61.         pass
  62.  
  63.     import posixpath as path
  64.     import posix
  65.     __all__.extend(_get_exports_list(posix))
  66.     del posix
  67. elif 'nt' in _names:
  68.     name = 'nt'
  69.     linesep = '\r\n'
  70.     from nt import *
  71.     
  72.     try:
  73.         from nt import _exit
  74.     except ImportError:
  75.         pass
  76.  
  77.     import ntpath as path
  78.     import nt
  79.     __all__.extend(_get_exports_list(nt))
  80.     del nt
  81. elif 'os2' in _names:
  82.     name = 'os2'
  83.     linesep = '\r\n'
  84.     from os2 import *
  85.     
  86.     try:
  87.         from os2 import _exit
  88.     except ImportError:
  89.         pass
  90.  
  91.     if sys.version.find('EMX GCC') == -1:
  92.         import ntpath as path
  93.     else:
  94.         import os2emxpath as path
  95.         from _emx_link import link
  96.     import os2
  97.     __all__.extend(_get_exports_list(os2))
  98.     del os2
  99. elif 'mac' in _names:
  100.     name = 'mac'
  101.     linesep = '\r'
  102.     from mac import *
  103.     
  104.     try:
  105.         from mac import _exit
  106.     except ImportError:
  107.         pass
  108.  
  109.     import macpath as path
  110.     import mac
  111.     __all__.extend(_get_exports_list(mac))
  112.     del mac
  113. elif 'ce' in _names:
  114.     name = 'ce'
  115.     linesep = '\r\n'
  116.     from ce import *
  117.     
  118.     try:
  119.         from ce import _exit
  120.     except ImportError:
  121.         pass
  122.  
  123.     import ntpath as path
  124.     import ce
  125.     __all__.extend(_get_exports_list(ce))
  126.     del ce
  127. elif 'riscos' in _names:
  128.     name = 'riscos'
  129.     linesep = '\n'
  130.     from riscos import *
  131.     
  132.     try:
  133.         from riscos import _exit
  134.     except ImportError:
  135.         pass
  136.  
  137.     import riscospath as path
  138.     import riscos
  139.     __all__.extend(_get_exports_list(riscos))
  140.     del riscos
  141. else:
  142.     raise ImportError, 'no os specific module found'
  143. sys.modules['os.path'] = path
  144. from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull
  145. del _names
  146. SEEK_SET = 0
  147. SEEK_CUR = 1
  148. SEEK_END = 2
  149.  
  150. def makedirs(name, mode = 511):
  151.     '''makedirs(path [, mode=0777])
  152.  
  153.     Super-mkdir; create a leaf directory and all intermediate ones.
  154.     Works like mkdir, except that any intermediate path segment (not
  155.     just the rightmost) will be created if it does not exist.  This is
  156.     recursive.
  157.  
  158.     '''
  159.     EEXIST = EEXIST
  160.     import errno
  161.     (head, tail) = path.split(name)
  162.     if not tail:
  163.         (head, tail) = path.split(head)
  164.     
  165.     if head and tail and not path.exists(head):
  166.         
  167.         try:
  168.             makedirs(head, mode)
  169.         except OSError:
  170.             e = None
  171.             if e.errno != EEXIST:
  172.                 raise 
  173.             
  174.         except:
  175.             e.errno != EEXIST
  176.  
  177.         if tail == curdir:
  178.             return None
  179.         
  180.     
  181.     mkdir(name, mode)
  182.  
  183.  
  184. def removedirs(name):
  185.     '''removedirs(path)
  186.  
  187.     Super-rmdir; remove a leaf directory and all empty intermediate
  188.     ones.  Works like rmdir except that, if the leaf directory is
  189.     successfully removed, directories corresponding to rightmost path
  190.     segments will be pruned away until either the whole path is
  191.     consumed or an error occurs.  Errors during this latter phase are
  192.     ignored -- they generally mean that a directory was not empty.
  193.  
  194.     '''
  195.     rmdir(name)
  196.     (head, tail) = path.split(name)
  197.     if not tail:
  198.         (head, tail) = path.split(head)
  199.     
  200.     while head and tail:
  201.         
  202.         try:
  203.             rmdir(head)
  204.         except error:
  205.             break
  206.  
  207.         (head, tail) = path.split(head)
  208.  
  209.  
  210. def renames(old, new):
  211.     '''renames(old, new)
  212.  
  213.     Super-rename; create directories as necessary and delete any left
  214.     empty.  Works like rename, except creation of any intermediate
  215.     directories needed to make the new pathname good is attempted
  216.     first.  After the rename, directories corresponding to rightmost
  217.     path segments of the old name will be pruned way until either the
  218.     whole path is consumed or a nonempty directory is found.
  219.  
  220.     Note: this function can fail with the new directory structure made
  221.     if you lack permissions needed to unlink the leaf directory or
  222.     file.
  223.  
  224.     '''
  225.     (head, tail) = path.split(new)
  226.     if head and tail and not path.exists(head):
  227.         makedirs(head)
  228.     
  229.     rename(old, new)
  230.     (head, tail) = path.split(old)
  231.     if head and tail:
  232.         
  233.         try:
  234.             removedirs(head)
  235.         except error:
  236.             pass
  237.         except:
  238.             None<EXCEPTION MATCH>error
  239.         
  240.  
  241.     None<EXCEPTION MATCH>error
  242.  
  243. __all__.extend([
  244.     'makedirs',
  245.     'removedirs',
  246.     'renames'])
  247.  
  248. def walk(top, topdown = True, onerror = None):
  249.     '''Directory tree generator.
  250.  
  251.     For each directory in the directory tree rooted at top (including top
  252.     itself, but excluding \'.\' and \'..\'), yields a 3-tuple
  253.  
  254.         dirpath, dirnames, filenames
  255.  
  256.     dirpath is a string, the path to the directory.  dirnames is a list of
  257.     the names of the subdirectories in dirpath (excluding \'.\' and \'..\').
  258.     filenames is a list of the names of the non-directory files in dirpath.
  259.     Note that the names in the lists are just names, with no path components.
  260.     To get a full path (which begins with top) to a file or directory in
  261.     dirpath, do os.path.join(dirpath, name).
  262.  
  263.     If optional arg \'topdown\' is true or not specified, the triple for a
  264.     directory is generated before the triples for any of its subdirectories
  265.     (directories are generated top down).  If topdown is false, the triple
  266.     for a directory is generated after the triples for all of its
  267.     subdirectories (directories are generated bottom up).
  268.  
  269.     When topdown is true, the caller can modify the dirnames list in-place
  270.     (e.g., via del or slice assignment), and walk will only recurse into the
  271.     subdirectories whose names remain in dirnames; this can be used to prune
  272.     the search, or to impose a specific order of visiting.  Modifying
  273.     dirnames when topdown is false is ineffective, since the directories in
  274.     dirnames have already been generated by the time dirnames itself is
  275.     generated.
  276.  
  277.     By default errors from the os.listdir() call are ignored.  If
  278.     optional arg \'onerror\' is specified, it should be a function; it
  279.     will be called with one argument, an os.error instance.  It can
  280.     report the error to continue with the walk, or raise the exception
  281.     to abort the walk.  Note that the filename is available as the
  282.     filename attribute of the exception object.
  283.  
  284.     Caution:  if you pass a relative pathname for top, don\'t change the
  285.     current working directory between resumptions of walk.  walk never
  286.     changes the current directory, and assumes that the client doesn\'t
  287.     either.
  288.  
  289.     Example:
  290.  
  291.     from os.path import join, getsize
  292.     for root, dirs, files in walk(\'python/Lib/email\'):
  293.         print root, "consumes",
  294.         print sum([getsize(join(root, name)) for name in files]),
  295.         print "bytes in", len(files), "non-directory files"
  296.         if \'CVS\' in dirs:
  297.             dirs.remove(\'CVS\')  # don\'t visit CVS directories
  298.     '''
  299.     join = join
  300.     isdir = isdir
  301.     islink = islink
  302.     import os.path
  303.     
  304.     try:
  305.         names = listdir(top)
  306.     except error:
  307.         err = None
  308.         if onerror is not None:
  309.             onerror(err)
  310.         
  311.         return None
  312.  
  313.     dirs = []
  314.     nondirs = []
  315.     for name in names:
  316.         if isdir(join(top, name)):
  317.             dirs.append(name)
  318.             continue
  319.         nondirs.append(name)
  320.     
  321.     if topdown:
  322.         yield (top, dirs, nondirs)
  323.     
  324.     for name in dirs:
  325.         path = join(top, name)
  326.         if not islink(path):
  327.             for x in walk(path, topdown, onerror):
  328.                 yield x
  329.             
  330.     
  331.     if not topdown:
  332.         yield (top, dirs, nondirs)
  333.     
  334.  
  335. __all__.append('walk')
  336.  
  337. try:
  338.     environ
  339. except NameError:
  340.     environ = { }
  341.  
  342.  
  343. def execl(file, *args):
  344.     '''execl(file, *args)
  345.  
  346.     Execute the executable file with argument list args, replacing the
  347.     current process. '''
  348.     execv(file, args)
  349.  
  350.  
  351. def execle(file, *args):
  352.     '''execle(file, *args, env)
  353.  
  354.     Execute the executable file with argument list args and
  355.     environment env, replacing the current process. '''
  356.     env = args[-1]
  357.     execve(file, args[:-1], env)
  358.  
  359.  
  360. def execlp(file, *args):
  361.     '''execlp(file, *args)
  362.  
  363.     Execute the executable file (which is searched for along $PATH)
  364.     with argument list args, replacing the current process. '''
  365.     execvp(file, args)
  366.  
  367.  
  368. def execlpe(file, *args):
  369.     '''execlpe(file, *args, env)
  370.  
  371.     Execute the executable file (which is searched for along $PATH)
  372.     with argument list args and environment env, replacing the current
  373.     process. '''
  374.     env = args[-1]
  375.     execvpe(file, args[:-1], env)
  376.  
  377.  
  378. def execvp(file, args):
  379.     '''execp(file, args)
  380.  
  381.     Execute the executable file (which is searched for along $PATH)
  382.     with argument list args, replacing the current process.
  383.     args may be a list or tuple of strings. '''
  384.     _execvpe(file, args)
  385.  
  386.  
  387. def execvpe(file, args, env):
  388.     '''execvpe(file, args, env)
  389.  
  390.     Execute the executable file (which is searched for along $PATH)
  391.     with argument list args and environment env , replacing the
  392.     current process.
  393.     args may be a list or tuple of strings. '''
  394.     _execvpe(file, args, env)
  395.  
  396. __all__.extend([
  397.     'execl',
  398.     'execle',
  399.     'execlp',
  400.     'execlpe',
  401.     'execvp',
  402.     'execvpe'])
  403.  
  404. def _execvpe(file, args, env = None):
  405.     ENOENT = ENOENT
  406.     ENOTDIR = ENOTDIR
  407.     import errno
  408.     if env is not None:
  409.         func = execve
  410.         argrest = (args, env)
  411.     else:
  412.         func = execv
  413.         argrest = (args,)
  414.         env = environ
  415.     (head, tail) = path.split(file)
  416.     if head:
  417.         func(file, *argrest)
  418.         return None
  419.     
  420.     if 'PATH' in env:
  421.         envpath = env['PATH']
  422.     else:
  423.         envpath = defpath
  424.     PATH = envpath.split(pathsep)
  425.     saved_exc = None
  426.     saved_tb = None
  427.     for dir in PATH:
  428.         fullname = path.join(dir, file)
  429.         
  430.         try:
  431.             func(fullname, *argrest)
  432.         continue
  433.         except error:
  434.             e = None
  435.             tb = sys.exc_info()[2]
  436.             if e.errno != ENOENT and e.errno != ENOTDIR and saved_exc is None:
  437.                 saved_exc = e
  438.                 saved_tb = tb
  439.             
  440.             saved_exc is None
  441.         
  442.  
  443.     
  444.     if saved_exc:
  445.         raise error, saved_exc, saved_tb
  446.     
  447.     raise error, e, tb
  448.  
  449.  
  450. try:
  451.     putenv
  452. except NameError:
  453.     pass
  454.  
  455. import UserDict
  456. if name in ('os2', 'nt'):
  457.     
  458.     def unsetenv(key):
  459.         putenv(key, '')
  460.  
  461.  
  462. if name == 'riscos':
  463.     from riscosenviron import _Environ
  464. elif name in ('os2', 'nt'):
  465.     
  466.     class _Environ(UserDict.IterableUserDict):
  467.         
  468.         def __init__(self, environ):
  469.             UserDict.UserDict.__init__(self)
  470.             data = self.data
  471.             for k, v in environ.items():
  472.                 data[k.upper()] = v
  473.             
  474.  
  475.         
  476.         def __setitem__(self, key, item):
  477.             putenv(key, item)
  478.             self.data[key.upper()] = item
  479.  
  480.         
  481.         def __getitem__(self, key):
  482.             return self.data[key.upper()]
  483.  
  484.         
  485.         try:
  486.             unsetenv
  487.         except NameError:
  488.             
  489.             def __delitem__(self, key):
  490.                 del self.data[key.upper()]
  491.  
  492.  
  493.         
  494.         def __delitem__(self, key):
  495.             unsetenv(key)
  496.             del self.data[key.upper()]
  497.  
  498.         
  499.         def has_key(self, key):
  500.             return key.upper() in self.data
  501.  
  502.         
  503.         def __contains__(self, key):
  504.             return key.upper() in self.data
  505.  
  506.         
  507.         def get(self, key, failobj = None):
  508.             return self.data.get(key.upper(), failobj)
  509.  
  510.         
  511.         def update(self, dict = None, **kwargs):
  512.             if dict:
  513.                 
  514.                 try:
  515.                     keys = dict.keys()
  516.                 except AttributeError:
  517.                     for k, v in dict:
  518.                         self[k] = v
  519.                     
  520.  
  521.                 for k in keys:
  522.                     self[k] = dict[k]
  523.                 
  524.             
  525.             if kwargs:
  526.                 self.update(kwargs)
  527.             
  528.  
  529.         
  530.         def copy(self):
  531.             return dict(self)
  532.  
  533.  
  534. else:
  535.     
  536.     class _Environ(UserDict.IterableUserDict):
  537.         
  538.         def __init__(self, environ):
  539.             UserDict.UserDict.__init__(self)
  540.             self.data = environ
  541.  
  542.         
  543.         def __setitem__(self, key, item):
  544.             putenv(key, item)
  545.             self.data[key] = item
  546.  
  547.         
  548.         def update(self, dict = None, **kwargs):
  549.             if dict:
  550.                 
  551.                 try:
  552.                     keys = dict.keys()
  553.                 except AttributeError:
  554.                     for k, v in dict:
  555.                         self[k] = v
  556.                     
  557.  
  558.                 for k in keys:
  559.                     self[k] = dict[k]
  560.                 
  561.             
  562.             if kwargs:
  563.                 self.update(kwargs)
  564.             
  565.  
  566.         
  567.         try:
  568.             unsetenv
  569.         except NameError:
  570.             pass
  571.  
  572.         
  573.         def __delitem__(self, key):
  574.             unsetenv(key)
  575.             del self.data[key]
  576.  
  577.         
  578.         def copy(self):
  579.             return dict(self)
  580.  
  581.  
  582. environ = _Environ(environ)
  583.  
  584. def getenv(key, default = None):
  585.     """Get an environment variable, return None if it doesn't exist.
  586.     The optional second argument can specify an alternate default."""
  587.     return environ.get(key, default)
  588.  
  589. __all__.append('getenv')
  590.  
  591. def _exists(name):
  592.     
  593.     try:
  594.         eval(name)
  595.         return True
  596.     except NameError:
  597.         return False
  598.  
  599.  
  600. if _exists('fork') and not _exists('spawnv') and _exists('execv'):
  601.     P_WAIT = 0
  602.     P_NOWAIT = P_NOWAITO = 1
  603.     
  604.     def _spawnvef(mode, file, args, env, func):
  605.         pid = fork()
  606.         if not pid:
  607.             
  608.             try:
  609.                 if env is None:
  610.                     func(file, args)
  611.                 else:
  612.                     func(file, args, env)
  613.             _exit(127)
  614.  
  615.         elif mode == P_NOWAIT:
  616.             return pid
  617.         
  618.         while None:
  619.             (wpid, sts) = waitpid(pid, 0)
  620.             if WIFSTOPPED(sts):
  621.                 continue
  622.                 continue
  623.             if WIFSIGNALED(sts):
  624.                 return -WTERMSIG(sts)
  625.                 continue
  626.             if WIFEXITED(sts):
  627.                 return WEXITSTATUS(sts)
  628.                 continue
  629.             raise error, 'Not stopped, signaled or exited???'
  630.             continue
  631.             return None
  632.  
  633.     
  634.     def spawnv(mode, file, args):
  635.         """spawnv(mode, file, args) -> integer
  636.  
  637. Execute file with arguments from args in a subprocess.
  638. If mode == P_NOWAIT return the pid of the process.
  639. If mode == P_WAIT return the process's exit code if it exits normally;
  640. otherwise return -SIG, where SIG is the signal that killed it. """
  641.         return _spawnvef(mode, file, args, None, execv)
  642.  
  643.     
  644.     def spawnve(mode, file, args, env):
  645.         """spawnve(mode, file, args, env) -> integer
  646.  
  647. Execute file with arguments from args in a subprocess with the
  648. specified environment.
  649. If mode == P_NOWAIT return the pid of the process.
  650. If mode == P_WAIT return the process's exit code if it exits normally;
  651. otherwise return -SIG, where SIG is the signal that killed it. """
  652.         return _spawnvef(mode, file, args, env, execve)
  653.  
  654.     
  655.     def spawnvp(mode, file, args):
  656.         """spawnvp(mode, file, args) -> integer
  657.  
  658. Execute file (which is looked for along $PATH) with arguments from
  659. args in a subprocess.
  660. If mode == P_NOWAIT return the pid of the process.
  661. If mode == P_WAIT return the process's exit code if it exits normally;
  662. otherwise return -SIG, where SIG is the signal that killed it. """
  663.         return _spawnvef(mode, file, args, None, execvp)
  664.  
  665.     
  666.     def spawnvpe(mode, file, args, env):
  667.         """spawnvpe(mode, file, args, env) -> integer
  668.  
  669. Execute file (which is looked for along $PATH) with arguments from
  670. args in a subprocess with the supplied environment.
  671. If mode == P_NOWAIT return the pid of the process.
  672. If mode == P_WAIT return the process's exit code if it exits normally;
  673. otherwise return -SIG, where SIG is the signal that killed it. """
  674.         return _spawnvef(mode, file, args, env, execvpe)
  675.  
  676.  
  677. if _exists('spawnv'):
  678.     
  679.     def spawnl(mode, file, *args):
  680.         """spawnl(mode, file, *args) -> integer
  681.  
  682. Execute file with arguments from args in a subprocess.
  683. If mode == P_NOWAIT return the pid of the process.
  684. If mode == P_WAIT return the process's exit code if it exits normally;
  685. otherwise return -SIG, where SIG is the signal that killed it. """
  686.         return spawnv(mode, file, args)
  687.  
  688.     
  689.     def spawnle(mode, file, *args):
  690.         """spawnle(mode, file, *args, env) -> integer
  691.  
  692. Execute file with arguments from args in a subprocess with the
  693. supplied environment.
  694. If mode == P_NOWAIT return the pid of the process.
  695. If mode == P_WAIT return the process's exit code if it exits normally;
  696. otherwise return -SIG, where SIG is the signal that killed it. """
  697.         env = args[-1]
  698.         return spawnve(mode, file, args[:-1], env)
  699.  
  700.     __all__.extend([
  701.         'spawnv',
  702.         'spawnve',
  703.         'spawnl',
  704.         'spawnle'])
  705.  
  706. if _exists('spawnvp'):
  707.     
  708.     def spawnlp(mode, file, *args):
  709.         """spawnlp(mode, file, *args) -> integer
  710.  
  711. Execute file (which is looked for along $PATH) with arguments from
  712. args in a subprocess with the supplied environment.
  713. If mode == P_NOWAIT return the pid of the process.
  714. If mode == P_WAIT return the process's exit code if it exits normally;
  715. otherwise return -SIG, where SIG is the signal that killed it. """
  716.         return spawnvp(mode, file, args)
  717.  
  718.     
  719.     def spawnlpe(mode, file, *args):
  720.         """spawnlpe(mode, file, *args, env) -> integer
  721.  
  722. Execute file (which is looked for along $PATH) with arguments from
  723. args in a subprocess with the supplied environment.
  724. If mode == P_NOWAIT return the pid of the process.
  725. If mode == P_WAIT return the process's exit code if it exits normally;
  726. otherwise return -SIG, where SIG is the signal that killed it. """
  727.         env = args[-1]
  728.         return spawnvpe(mode, file, args[:-1], env)
  729.  
  730.     __all__.extend([
  731.         'spawnvp',
  732.         'spawnvpe',
  733.         'spawnlp',
  734.         'spawnlpe'])
  735.  
  736. if _exists('fork'):
  737.     if not _exists('popen2'):
  738.         
  739.         def popen2(cmd, mode = 't', bufsize = -1):
  740.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  741.             may be a sequence, in which case arguments will be passed directly to
  742.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  743.             is a string it will be passed to the shell (as with os.system()). If
  744.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  745.             file objects (child_stdin, child_stdout) are returned."""
  746.             import popen2
  747.             (stdout, stdin) = popen2.popen2(cmd, bufsize)
  748.             return (stdin, stdout)
  749.  
  750.         __all__.append('popen2')
  751.     
  752.     if not _exists('popen3'):
  753.         
  754.         def popen3(cmd, mode = 't', bufsize = -1):
  755.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  756.             may be a sequence, in which case arguments will be passed directly to
  757.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  758.             is a string it will be passed to the shell (as with os.system()). If
  759.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  760.             file objects (child_stdin, child_stdout, child_stderr) are returned."""
  761.             import popen2
  762.             (stdout, stdin, stderr) = popen2.popen3(cmd, bufsize)
  763.             return (stdin, stdout, stderr)
  764.  
  765.         __all__.append('popen3')
  766.     
  767.     if not _exists('popen4'):
  768.         
  769.         def popen4(cmd, mode = 't', bufsize = -1):
  770.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  771.             may be a sequence, in which case arguments will be passed directly to
  772.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  773.             is a string it will be passed to the shell (as with os.system()). If
  774.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  775.             file objects (child_stdin, child_stdout_stderr) are returned."""
  776.             import popen2
  777.             (stdout, stdin) = popen2.popen4(cmd, bufsize)
  778.             return (stdin, stdout)
  779.  
  780.         __all__.append('popen4')
  781.     
  782.  
  783. import copy_reg as _copy_reg
  784.  
  785. def _make_stat_result(tup, dict):
  786.     return stat_result(tup, dict)
  787.  
  788.  
  789. def _pickle_stat_result(sr):
  790.     (type, args) = sr.__reduce__()
  791.     return (_make_stat_result, args)
  792.  
  793.  
  794. try:
  795.     _copy_reg.pickle(stat_result, _pickle_stat_result, _make_stat_result)
  796. except NameError:
  797.     pass
  798.  
  799.  
  800. def _make_statvfs_result(tup, dict):
  801.     return statvfs_result(tup, dict)
  802.  
  803.  
  804. def _pickle_statvfs_result(sr):
  805.     (type, args) = sr.__reduce__()
  806.     return (_make_statvfs_result, args)
  807.  
  808.  
  809. try:
  810.     _copy_reg.pickle(statvfs_result, _pickle_statvfs_result, _make_statvfs_result)
  811. except NameError:
  812.     pass
  813.  
  814. if not _exists('urandom'):
  815.     
  816.     def urandom(n):
  817.         '''urandom(n) -> str
  818.  
  819.         Return a string of n random bytes suitable for cryptographic use.
  820.  
  821.         '''
  822.         
  823.         try:
  824.             _urandomfd = open('/dev/urandom', O_RDONLY)
  825.         except (OSError, IOError):
  826.             raise NotImplementedError('/dev/urandom (or equivalent) not found')
  827.  
  828.         bytes = ''
  829.         while len(bytes) < n:
  830.             bytes += read(_urandomfd, n - len(bytes))
  831.         close(_urandomfd)
  832.         return bytes
  833.  
  834.  
  835.